package jee.boot.common.rest;

import jee.boot.common.basic.CrudController;
import jee.boot.common.basic.Page;
import jee.boot.common.basic.result.ResponseMessage;
import jee.boot.common.basic.result.Result;
import jee.boot.common.service.TreeNodeService;
import jee.boot.entity.system.TreeNode;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 树节点
 */
@RestController
@RequestMapping("/treeNode")
public class TreeNodeRestController extends CrudController<TreeNodeService, TreeNode> {
    @Override
    public ResponseMessage<TreeNode> save(@RequestBody @Validated TreeNode entity) {
        return super.save(entity);
    }

    @Override
    public ResponseMessage<TreeNode> update(@RequestBody @Validated TreeNode entity) {

        return super.update(entity);
    }
    /**
     * 树
     *
     * @param entity
     * @return
     */
    @PostMapping("/treeData")
    public ResponseMessage<List<TreeNode>> treeData(@RequestBody TreeNode entity) {
        List<TreeNode> tree= service.treeData(entity);
        return Result.success(tree);

    }

    @Override
    public ResponseMessage<Page<TreeNode>> list(@RequestBody TreeNode entity) {
        entity.setCascadeEntity(true);
        return super.list(entity);
    }
}
